package br.com.infocruz.seam.crm.ejb.session;

import br.com.infocruz.seam.crm.ejb.model.*;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("userAuthorizationHome")
public class UserAuthorizationHome extends EntityHome<UserAuthorization> {

	@In(create = true)
	UserHome userHome;

	public void setUserAuthorizationId(Long id) {
		setId(id);
	}

	public Long getUserAuthorizationId() {
		return (Long) getId();
	}

	@Override
	protected UserAuthorization createInstance() {
		UserAuthorization userAuthorization = new UserAuthorization();
		return userAuthorization;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		User user = userHome.getDefinedInstance();
		if (user != null) {
			getInstance().setUser(user);
		}
	}

	public boolean isWired() {
		return true;
	}

	public UserAuthorization getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

}
